package com.oocl.ita.qqclientt;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.ita.sakura.client.Client;
import com.oocl.ita.serverlistenner.ServerListener;
import com.oocl.ita.ui.ChatFrame;
import com.oocl.ita.ui.LoginFrame;

public class QQClient {

	private static Client client;
	private static Client toClient = new Client("All");
	private static List<Client> contactList = new ArrayList();
	private static ObjectOutputStream oos;
	private static ObjectInputStream ois;
	private static ChatFrame chatFrame;
	/*
	 * 1, 登录窗口 
	 * 2, 初始化到服务器的连接 
	 * 3, 获取一个oos, ois 
	 * 4, 监听Server的Protocol
	 */

	public void start(String IP, int port) throws UnknownHostException, IOException {
		Socket socket = new Socket(IP, port);
		this.ois = new ObjectInputStream(socket.getInputStream());
		this.oos = new ObjectOutputStream(socket.getOutputStream());
		LoginFrame loginFrame = new LoginFrame();
		loginFrame.setVisible(true);
	}

	public static void main(String[] args) throws UnknownHostException, IOException {
		QQClient oo = new QQClient();
		oo.start("127.0.0.1", 8888);
		new Thread(new ServerListener()).start();
	}

	public static synchronized Client getClient() {
		return client;
	}

	public static synchronized void setClient(Client client) {
		QQClient.client = client;
	}

	public static synchronized Client getToClient() {
		return toClient;
	}

	public static synchronized void setToClient(Client toClient) {
		QQClient.toClient = toClient;
	}

	public static synchronized List<Client> getContactList() {
		return contactList;
	}

	public static synchronized void setContactList(List<Client> contactList) {
		QQClient.contactList = contactList;
	}

	public static synchronized ObjectOutputStream getOos() {
		return oos;
	}

	public static synchronized void setOos(ObjectOutputStream oos) {
		QQClient.oos = oos;
	}

	public static synchronized ObjectInputStream getOis() {
		return ois;
	}

	public static synchronized void setOis(ObjectInputStream ois) {
		QQClient.ois = ois;
	}

	public static synchronized ChatFrame getChatFrame() {
		return chatFrame;
	}

	public static synchronized void setChatFrame(ChatFrame chatFrame) {
		QQClient.chatFrame = chatFrame;
	}

	
}
